﻿function widgetEventos(data) {
    var css_link = $("<link>", {
        rel: "stylesheet",
        type: "text/css",
        href: "http://localhost:49357/Services/Widget/style.css"
    });
    css_link.appendTo('head'); 
    fetchProximos(data.cant, data.target);
}

function fetchProximos(cant, target) {
    $(target).attr("class", "contenedor-widget")
    $("<a></a>", {
        "class": "link-widget",
        "id": "link-widget",
        "href": "http://localhost:49357/",
        "text": "Próximos Eventos",
        "target":"_blank"
    }).appendTo(target)
    $("<table></table>", {
        "class": "tabla-widget",
        "id": "tabla-widget"
    }).appendTo(target)
    $.getJSON(
        "http://localhost:49357/Services/EventosAJAX.svc/ProximosEventos",
        {
            "cant": cant
        },
        function (data) {
            $.each(data, function (index) {
                var link = '<a target = "_blank" href = '+data[index].Link+">"+data[index].Nombre+"</a>"
                var linea = "<tr><td>" + link + "</td>" + '<td class = "texto">' + data[index].Fecha + "</td><tr>"
                $("#tabla-widget").append(linea);
            })
        }
    );
}
